package org.example.salesystem.service.impl;

import org.example.salesystem.entity.Complaint;
import org.example.salesystem.mapper.ComplaintMapper;
import org.example.salesystem.service.ComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ComplaintServiceImpl implements ComplaintService {
    @Autowired
    private ComplaintMapper complaintMapper;

    @Override
    public List<Complaint> getUserComplaints(String reporterPhone) {
        return complaintMapper.getByReporterPhone(reporterPhone);
    }

    @Override
    public List<Complaint> getSellerComplaints() {
        return complaintMapper.getAll();
    }

    @Override
    public void approveComplaint(Long id, String productId, String reporterPhone) {
        Complaint complaint = new Complaint();
        complaint.setId(id);
        complaint.setProductId(productId);
        complaint.setReporterPhone(reporterPhone);
        complaint.setStatus(1);
        complaint.setFeedbackTime(LocalDateTime.now());
        complaintMapper.updateStatus(complaint);
    }

    @Override
    public void rejectComplaint(Long id, String productId, String reporterPhone, String feedback) {
        Complaint complaint = new Complaint();
        complaint.setId(id);
        complaint.setProductId(productId);
        complaint.setReporterPhone(reporterPhone);
        complaint.setStatus(2);
        complaint.setFeedback(feedback);
        complaint.setFeedbackTime(LocalDateTime.now());
        complaintMapper.updateStatus(complaint);
    }
} 